Dynamic treeviews can be created on the server side or client side. When creating a dynamic treeview on the server side, use a constructor to dynamically create a new instance of the C1TreeView class. For example:
Visual Basic |
Copy Code
|
---|---|
Namespace TreeViewQuickStart Public Partial Class MainPage Inherits UserControl Public Sub New() InitializeComponent() InitializeTreeView() End Sub Private Sub InitializeTreeView() ' Remove items that were added at design time Tree.Items.Clear() Dim booklist As New C1TreeViewItem() booklist.Header = "Book List" Tree.Items.Add(booklist) ' Adding child items Dim language As New C1TreeViewItem() language.Header = "Language Books" booklist.Items.Add(language) ' Adding child items Dim security As New C1TreeViewItem() security.Header = "Security Books" booklist.Items.Add(security) ' Adding child items Dim classic As New C1TreeViewItem() classic.Header = "Classic Books" booklist.Items.Add(classic) ' Adding child items Dim subclassic As New C1TreeViewItem() subclassic.Header = "Catch-22" classic.Items.Add(subclassic) Dim subclassic2 As New C1TreeViewItem() subclassic2.Header = "The Great Gatsby" classic.Items.Add(subclassic2) End Sub End Class End Namespace |
C# |
Copy Code
|
---|---|
namespace TreeViewQuickStart { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); InitializeTreeView(); } void InitializeTreeView() { // Remove items that were added at design time Tree.Items.Clear(); C1TreeViewItem booklist = new C1TreeViewItem(); booklist.Header = "Book List"; Tree.Items.Add(booklist); // Adding child items C1TreeViewItem language = new C1TreeViewItem(); language.Header = "Language Books"; booklist.Items.Add( language ); // Adding child items C1TreeViewItem security = new C1TreeViewItem(); security.Header = "Security Books"; booklist.Items.Add(security); // Adding child items C1TreeViewItem classic = new C1TreeViewItem(); classic.Header = "Classic Books"; booklist.Items.Add(classic); // Adding child items C1TreeViewItem subclassic = new C1TreeViewItem(); subclassic.Header = "Catch-22"; classic.Items.Add(subclassic); C1TreeViewItem subclassic2 = new C1TreeViewItem(); subclassic2.Header = "The Great Gatsby"; classic.Items.Add(subclassic2); } } } |